import json
import os
from dotenv import load_dotenv
from fastapi import APIRouter
from pydantic import BaseModel
from ..models.ai_models.search_api import run_coze_workflow as search_it_online
search_onliner=APIRouter(prefix="/search-online", tags=["联网搜索"])

load_dotenv()
API_TOKEN=os.getenv("API_TOKEN")
@search_onliner.get("/")
async def hello_search_online():
    return {"message": "Hello World"}

class SearchOnlineParams(BaseModel):
    query: str = ...
@search_onliner.post("/")
async def search_online(params: SearchOnlineParams):
    result_start = search_it_online(params.query, "7529426430200987711", API_TOKEN)
    content_dict = json.loads(result_start[0].content)
    result=content_dict["output"]
    return {
        "code": 200,
        "message": "success",
        "data": result
    }